// JScript File

function createInputElement(tipo, id, valor, classe, titulo) {
  var objInput = document.createElement('INPUT');
  if(!titulo) titulo = '';
  objInput.type = tipo;
  objInput.id = id;
  objInput.name = id;
  objInput.value = valor;
  objInput.title = titulo;
  objInput.className = classe;
  
  return objInput;
}

function createLabelElement(id, valor, classe) {
  var objLabel = document.createElement('LABEL');
  
  objLabel.id = id;
  objLabel.name = id;
  objLabel.value = valor;
  objLabel.className = classe;
  
  return objLabel;
}

function createSelectElement(id, itens, classe, title, padrao) {
  var x, i;
  var objSelect = document.createElement('SELECT');
  
  objSelect.id = id;
  objSelect.name = id;
  objSelect.className = classe;
  if (title) objSelect.title = title;
  
  if(itens.length) {
    for(x = 0, i = 0; x < itens.length; x += 2, i++) {
      // (nome, valor)
      objSelect.options[i] = new Option(itens[x],itens[x+1]);
      if(padrao == itens[x+1]) objSelect.selectedIndex = i;
    }
  }
  
  return objSelect;
}

/**
action: pagina que vai processar o formulario
dados : array no formato [chave1,valor1,...,chaven,valorn]
**/
function createSubmitForm(action,dados) {
  var form = document.createElement('form');
  form.action = action;
  form.method = 'post';
  for(var x = 0; x < dados.length; x += 2) {
    var campo = document.createElement('input');
    campo.type = 'hidden';
    campo.name = dados[x];
    campo.value = dados[x+1];
    form.appendChild(campo);
  }
  document.getElementsByTagName('body')[0].appendChild(form);
  form.submit();
}

function createImage(id, src, alt, titulo) {
  var ObjImg = document.createElement('IMG');
  
  ObjImg.id = id;
  ObjImg.src = src;
  ObjImg.alt = alt;
  ObjImg.title = titulo;
  ObjImg.border = '0';
  
  return ObjImg;
}